#include "TimeUtility.h"

string TimeUtility::Now(bool bFileNameFriendly)
{
	time_t rawtime;
	time(&rawtime);
	tm timeinfo;
	localtime_s(&timeinfo,&rawtime);

	int year=timeinfo.tm_year+1900;
	int month=timeinfo.tm_mon+1;
	int day=timeinfo.tm_mday;
	int hour=timeinfo.tm_hour;
	int min=timeinfo.tm_min;
	int sec=timeinfo.tm_sec;
	string seperator=bFileNameFriendly?"-":":";

	stringstream ss;
	ss<<Pad(year,4)<<"-"<<Pad(month,2)<<"-"<<Pad(day,2)<<" "<<Pad(hour,2)<<seperator<<Pad(min,2)<<seperator<<Pad(sec,2);

	return ss.str();
}
string TimeUtility::Today()
{
	time_t rawtime;
	time(&rawtime);
	tm timeinfo;
	localtime_s(&timeinfo,&rawtime);
	int year=timeinfo.tm_year+1900;
	int month=timeinfo.tm_mon+1;
	int day=timeinfo.tm_mday;
	stringstream ss;
	ss<<year<<"-"<<month<<"-"<<day;
	return ss.str();
}

string TimeUtility::Pad(int val,int length)
{
	stringstream ss;
	ss.fill('0');
	ss.width(length);
	ss<<val;
	return ss.str();
}